/* ===================

AX2E (AXESCON XACML 2.0 Engine) is the Java authorization engine, which implements OASIS XACML 2.0 standard.
Copyright (C) 2007 AXESCON LLC

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA


Contact: AXESCON LLC - info{at}axescon.com

 =================== */
/*
 * XML Type:  Result
 * Namespace: urn:oasis:names:tc:xacml:2.0:context:schema:os
 * Java type: axescon.xacml.model.ctx.Result
 *
 * Automatically generated - do not modify.
 */
package axescon.xacml.model.ctx.impl;

import axescon.xacml.model.ctx.Status;
import axescon.xacml.model.ctx.StatusCode;
import axescon.xacml.model.explain.Explanation;
import axescon.xacml.model.policy.Obligation;
import axescon.xacml.model.shared.Decision;
import axescon.xacml.api.XacmlException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * An XML Result(@urn:oasis:names:tc:xacml:2.0:context:schema:os).
 * <p/>
 * This is a complex type.
 */
public class ResultImpl implements axescon.xacml.model.ctx.Result {

    private byte decision;

    private Status status = new StatusImpl(StatusCode.INT_OK);

    /**
     * List<Obligation>
     */
    private List obligationList;

    private String resourceId;

    public byte getDecision() {
        return decision;
    }

    public void setDecision(byte decision) {
        this.decision = decision;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }


    public String getResourceId() {
        return resourceId;
    }

    public void setResourceId(String resourceId) {
        this.resourceId = resourceId;
    }

    public List getObligationList() {
        return obligationList;
    }

    public void setObligationArray(Obligation[] obligationArray) {
        if (obligationArray != null && obligationArray.length == 0) return;
        this.obligationList = new ArrayList(Arrays.asList(obligationArray));
    }

    public void addObligationArray(Obligation[] obligationArray) {
        if (obligationArray == null) return;
        if (obligationArray.length == 0) return;

        for (int i = 0; i < obligationArray.length; i++) {
            Obligation obl = obligationArray[i];
            if (obl.getFulfillOn() == getDecision()) {
                if (obligationList == null) obligationList = new ArrayList(obligationArray.length);
                obligationList.add(obl);
            }
        }
    }

    public Explanation explanation;

    public Explanation getExplanation() {
        return explanation;
    }

    public void setExplanation(Explanation explanation) {
        this.explanation = explanation;
    }

    public String getDecisionString() {
        return Decision.toString(getDecision());
    }

    XacmlException  xacmlException;

    public XacmlException getXacmlException() {
        return xacmlException;
    }

    public void setXacmlException(XacmlException xacmlException) {
        this.xacmlException = xacmlException;
    }
}
